<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">

      
        <!-- 搜索 -->
<!--  

        <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
          <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
        </el-select>

        

        <el-date-picker
          v-model="query.createTime"
          :default-time="['00:00:00','23:59:59']"
          type="daterange"
          range-separator=":"
          size="small"
          class="date-item"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="createTimeStart"
          end-placeholder="createTimeEnd"
        />
        <el-date-picker
          v-model="query.updateTime"
          :default-time="['00:00:00','23:59:59']"
          type="daterange"
          range-separator=":"
          size="small"
          class="date-item"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="updateTimeStart"
          end-placeholder="updateTimeEnd"
        />
      

        <rrOperation :crud="crud" />
-->

      </div>

      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <!--
      <crudOperation :permission="permission" />
      -->
      
      
      
      <!--表单组件-->
      <el-dialog style="z-index:1 !important; " :modal="false" :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="1000px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          
          <el-form-item label="标题">
            <el-input disabled v-model="form.title" style="width: 90%;" />
          </el-form-item>
          <el-form-item label="url">
            <el-input v-model="form.url" style="width: 90%;" />
          </el-form-item>
          <el-form-item label="描述">
<ueditor-wrap v-model="form.message" :config="myConfig" @beforeInit="addCustomDialog"
                            style="width: 90%;" ></ueditor-wrap>
              
<!--
          <el-input :rows="3" v-model="form.message" type="textarea" style="width: 90%;" />
            
            
            -->
          </el-form-item>
          
          <el-form-item label="排序">
            <el-input type="number" v-model="form.weight" style="width: 90%;" />
          </el-form-item>
          <el-form-item label="客服电话">
            <el-input  v-model="form.phone" style="width: 90%;" />
          </el-form-item>

          <!--


          <el-form-item label="主键id">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建时间">
            <el-date-picker v-model="form.createTime" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="编辑时间">
            <el-date-picker v-model="form.updateTime" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="删除(0存/1删)">
            <el-input v-model="form.isDel" style="width: 370px;" />
          </el-form-item>
          -->
          
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('id')" prop="id" label="id" />
        <el-table-column v-if="columns.visible('title')" prop="title" label="标题" />
        
        
        <el-table-column v-if="columns.visible('weight')" prop="weight" label="排序" />
        <el-table-column v-if="columns.visible('createTime')" prop="createTime" label="创建时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>

        <!--
        <el-table-column v-if="columns.visible('url')" prop="url" label="url" />
        <el-table-column v-if="columns.visible('message')" prop="message" label="内容" />
        <el-table-column v-if="columns.visible('updateTime')" prop="updateTime" label="编辑时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updateTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('isDel')" prop="isDel" label="删除(0存/1删)" />
-->

        <el-table-column v-permission="['admin','yxUserHelpCenter:edit']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
       <el-button v-permission="['admin','yxUserHelpCenter:edit']" :disabled="disabledEdit" size="mini" type="primary" icon="el-icon-edit" @click="crud.toEdit(scope.row)" />

       <!--
       <udOperation
              :data="scope.row"
              :permission="permission"
            />
       
       -->
        
            
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudYxUserHelpCenter from '@/api/yxUserHelpCenter'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import MaterialList from "@/components/material";
import UeditorWrap from 'vue-ueditor-wrap';

// crud交由presenter持有
const defaultCrud = CRUD({ title: '', url: 'api/yxUserHelpCenter', sort: 'id,desc', crudMethod: { ...crudYxUserHelpCenter }})
const defaultForm = { id: null, url: null, message: null, title: null, weight: null, createTime: null, updateTime: null, isDel: null }
export default {
  name: 'YxUserHelpCenter',
  components: { pagination, crudOperation, rrOperation, udOperation ,MaterialList, UeditorWrap},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {
      myConfig: {
        autoHeightEnabled: false, // 编辑器不自动被内容撑高
        initialFrameHeight: 200, // 初始容器高度
        initialFrameWidth: '100%', // 初始容器宽度
        UEDITOR_HOME_URL: '/UEditor/',
        serverUrl: ''
      },
      permission: {
         edit: ['admin','yxUserHelpCenter:edit']
      },
      rules: {


      },
      queryTypeOptions: [
        { key: 'id', display_name: '主键id' },
        { key: 'url', display_name: '跳转url' },
        { key: 'message', display_name: '描述' },
        { key: 'title', display_name: '标题' },
        { key: 'weight', display_name: '排序' },
        { key: 'phone', display_name: '客服电话' },
        { key: 'isDel', display_name: '删除(0存/1删)' }
      ]
    }
  },
  watch: {
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }else{
        delete this.crud.params.id
        delete this.crud.params.url
        delete this.crud.params.message
        delete this.crud.params.title
        delete this.crud.params.weight
        delete this.crud.params.isDel
      }
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
    addCustomDialog () {
      window.UE.registerUI('yshop', function (editor, uiName) {
        let dialog = new window.UE.ui.Dialog({
          iframeUrl: '/yshop/materia/index',
          editor: editor,
          name: uiName,
          title: '上传图片',
          cssRules: 'width:1200px;height:500px;padding:20px;'
        });
        this.dialog = dialog;

        var btn = new window.UE.ui.Button({
          name: 'dialog-button',
          title: '上传图片',
          cssRules: `background-image: url(../../../assets/images/icons.png);background-position: -726px -77px;`,
          onclick: function () {
            dialog.render();
            dialog.open();

            // 获取对话框的DOM元素并设置其位置  
            let dialogDom = dialog.getDom();  
            dialogDom.style.position = 'absolute';  
            dialogDom.style.top = '50px'; // 根据需要调整  
            dialogDom.style.left = '50%'; // 根据需要调整  
            dialogDom.style.transform = 'translateX(-50%)'; // 水平居中  
            dialogDom.style.zIndex = '999999999'; // 确保z-index足够高
          }
        });

        return btn;
      }, 37);
    },
  }
}



</script>

<style scoped>
/deep/ .el-dialog__wrapper {
  z-index:5 !important; 
}
/deep/ .v-modal {
  z-index:0 !important; 
}
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
